use opencv::{highgui, prelude::*, videoio};

#[test]
fn run() -> anyhow::Result<()> {
    let window = "video capture";
    highgui::named_window(window, highgui::WINDOW_AUTOSIZE)?;

    let mut video_cap =
        videoio::VideoCapture::from_file("/home/jaakan/下载/超级飞侠9/11.mp4", videoio::CAP_ANY)
            .unwrap();

    let opened = videoio::VideoCapture::is_opened(&video_cap)?;
    if !opened {
        panic!("Unable to open default camera!");
    }
    loop {
        let mut frame = Mat::default();
        video_cap.read(&mut frame)?;
        if frame.size()?.width > 0 {
            highgui::imshow(window, &frame)?;
        }
        let dur = std::time::Duration::from_millis(100);
        std::thread::sleep(dur);

        let key = highgui::wait_key(10)?;
        if key > 0 && key != 255 {
            break;
        }
    }
    Ok(())
}
